nlp_architect.models.np_semantic_segmentation.NpSemanticSegClassifier

class nlp_architect.models.np_semantic_segmentation.NpSemanticSegClassifier(num_epochs, callback_args, loss='binary_crossentropy', optimizer='adam', batch_size=128)[source]

NP Semantic Segmentation classifier model (based on tf.Keras framework).

Parameters:
  • num_epochs (int) – number of epochs to train the model
  • **callback_args (dict) – callback args keyword arguments to init a Callback for the model
  • loss – the model’s cost function. Default is ‘tf.keras.losses.binary_crossentropy’ loss
  • optimizer (tf.keras.optimizers) – the model’s optimizer. Default is ‘adam’
__init__(num_epochs, callback_args, loss='binary_crossentropy', optimizer='adam', batch_size=128)[source]
Parameters:
  • num_epochs (int) – number of epochs to train the model
  • callback_args (dict) – callback args keyword arguments to init Callback for the model
  • loss – the model’s loss function. Default is ‘tf.keras.losses.binary_crossentropy’ loss
  • optimizer (tf.keras.optimizers) – the model’s optimizer. Default is adam
  • batch_size (int) – batch size

Methods

__init__(num_epochs, callback_args[, loss, …])
param num_epochs:
 number of epochs to train the model
build(input_dim) Build the model’s layers :param input_dim: the first layer’s input_dim :type input_dim: int
eval(test_set) Evaluate the model’s test_set on error_rate, test_accuracy_rate and precision_recall_rate
fit(train_set) Train and fit the model on the datasets
get_outputs(test_set) Classify the dataset on the model
load(model_path) Load pre-trained model’s .h5 file to NpSemanticSegClassifier object
save(model_path) Save the model’s prm file in model_path location
build(input_dim)[source]

Build the model’s layers :param input_dim: the first layer’s input_dim :type input_dim: int

eval(test_set)[source]

Evaluate the model’s test_set on error_rate, test_accuracy_rate and precision_recall_rate

Parameters:test_set (numpy.ndarray) – The test set
Returns:loss, binary_accuracy, precision, recall and f1 measures
Return type:tuple(float)
fit(train_set)[source]

Train and fit the model on the datasets

Parameters:
  • train_set (numpy.ndarray) – The train set
  • args – callback_args and epochs from ArgParser input
get_outputs(test_set)[source]

Classify the dataset on the model

Parameters:test_set (numpy.ndarray) – The test set
Returns:model’s predictions
Return type:list(numpy.ndarray)
load(model_path)[source]

Load pre-trained model’s .h5 file to NpSemanticSegClassifier object

Parameters:model_path (str) – local path for loading the model
save(model_path)[source]

Save the model’s prm file in model_path location

Parameters:model_path (str) – local path for saving the model